package leetcode;

public class NumOfWord {

    static public int countSegments(String s) {
        int i,j,count = 0;
        for (i = 0; i < s.length(); i++) {
            if(!(Character.isLetter(s.charAt(i)))){
                continue;
            }
            for (j = i+1; j < s.length(); j++) {
                if(Character.isLetter(s.charAt(j))||s.charAt(j) == '\''){
                    continue;
                }else {
                    count++;
                    i = j;
                    break;
                }
            }
        }
        if(Character.isLetter(s.charAt(s.length()-1))){
            return count+1;
        }else{
            return count;
        }
    }

    public static void main(String[] args) {
        String s = "i wern love live! mu'sic forever";
        System.out.println(countSegments(s));
        String food1 = args[1];

    }
}
